package com.certificationManager.server.service;

import com.certificationManager.client.bean.UserBean;
import com.certificationManager.client.service.UserService;
import com.certificationManager.server.domain.dao.jdo.UserDAOJdo;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

/**
 * @author Benjamin Barbier
 *
 */
public class UserServiceImpl extends RemoteServiceServlet implements
		UserService {

	/** Serial */
	private static final long serialVersionUID = 1L;

	@Override
	public void register(UserBean user) throws Exception{
		
		if (UserDAOJdo.getInstance().existUtilisateur(user.getEmail())) {
			throw new Exception("This email address is already linked to an account: "+user.getEmail()+".");
		}

		UserDAOJdo.getInstance().inscription(user);
		
	}

	@Override
	public boolean isRegistered(String email, String password) {
		return UserDAOJdo.getInstance().isRegistered(email, password);
	}

	/* (non-Javadoc)
	 * @see com.certificationManager.client.service.UserService#getUser(java.lang.String)
	 */
	@Override
	public UserBean getUser(String key) {
		//TODO: Update GetUser
		System.out.println("GET USER");
		UserBean result = new UserBean();
		result.setEmail("mail@test.fr");
		result.setFirstName("bob");
		result.setLastName("dylan");
		result.setKey("key0000000001");
		return result;
	}

}
